package com.dnfm.game.equip.service;

import com.dnfm.game.equip.common.MapperService;
import com.dnfm.game.equip.model.MonsterAttribute;
import com.dnfm.game.equip.model.RoleAttribute;
import com.dnfm.game.equip.model.SkillLine;
import com.dnfm.game.equip.pojo.EquipAttribute;

import java.util.ArrayList;
import java.util.List;


public class ActService {


    public static List<SkillLine> realActPrint(List<Integer> schemeIds, List<EquipAttribute> equips, RoleAttribute roleAttribute, MonsterAttribute monsterAttribute) {
        StringBuilder sb = new StringBuilder();
        List<EquipAttribute> list = MapperService.equipAttributeMapper.selectBySchemeIds(schemeIds);
        list.addAll(equips);
        list.forEach(a->{
            sb.append(a.getSchemeName()).append("\r\n");
        });
        EquipAttribute attribute = DamageService.computePanel(list);
        Double panelPower = PanelService.getPanelPower(attribute.getBasePower(), attribute.getPowerRate());
        Double panelAct = PanelService.getPanelAct(panelPower, attribute.getBaseAttack(), attribute.getAttackRate());

        sb.append("面板:\r\n")
                .append("-力量:").append(panelPower).append("\r\n")
                .append("-攻击:").append(panelAct).append("\r\n")
                .append("-属强:").append(attribute.getAttributeEnhanced()).append("\r\n")
//                .append("-命中:").append(attribute.getHit()).append("\r\n")
//                .append("-命中率:").append(attribute.getHitRate()).append("\r\n")
        ;

        sb.append("伤害:\r\n");
        roleAttribute.setEnhanced(true);
        List<SkillLine> list1 = realAct(attribute, roleAttribute, monsterAttribute);

        for (SkillLine skillLine : list1) {
            sb.append("-").append(skillLine.getSkillName()).append("\r\n");
            sb.append("--暴击:").append(skillLine.getCriticalStrike()).append("\r\n");
            sb.append("--暴击最大:").append(skillLine.getMax()).append("\r\n");
            sb.append("--暴击最小:").append(skillLine.getMin()).append("\r\n");
            sb.append("--期望:").append(skillLine.getExpectation()).append("\r\n");
            sb.append("--不暴击:").append(skillLine.getNoCriticalStrike()).append("\r\n");
        }
        System.out.println(sb);
        return list1;
    }


    public static List<SkillLine> realAct(EquipAttribute attribute, RoleAttribute roleAttribute, MonsterAttribute monsterAttribute) {
        //基础攻击加成
        Double act = DamageService.computeAttack(attribute);
        //基础力量加成
        Double power = DamageService.computePower(attribute);
        //防御系数
        Double def = DamageService.computeDefense(attribute, roleAttribute, monsterAttribute);
        //伤害增加 黄字加成
        Double damageIncrease = DamageService.computeDamageIncrease(attribute);
        //伤害附加 白字加成
        Double computeAdditive = DamageService.computeAdditive(attribute);
        //技攻加成
        Double computeSkillIncrease = DamageService.computeSkillIncrease(attribute);


        //以上加成计算
        Double reaAct = act * power * def *
                damageIncrease * computeAdditive *
                computeSkillIncrease;

        //属强计算
        if (roleAttribute.isEnhanced()) {
            Double enhanced = DamageService.computeAttributeEnhanced(attribute);
            reaAct = reaAct * enhanced;
        }

        //暴击增伤
        Double strikeDamage = DamageService.computeCriticalStrikeDamage(attribute);
        //暴击率
        Double strikeRate = DamageService.computeCriticalStrikeRate(attribute, monsterAttribute.getMonsterLevel());
        //暴击期望增伤
        Double strikeDamageWhitRate = DamageService.computeCriticalStrikeDamageWithRate(attribute, strikeRate);


        List<SkillLine> list = new ArrayList<>();
        for (SkillLine sk : roleAttribute.getSkillLine()) {
            Double noCriticalStrike = sk.getSkillRate() * reaAct;
            sk.setCriticalStrike(noCriticalStrike * strikeDamage);
            sk.setNoCriticalStrike(noCriticalStrike);
            sk.setExpectation(noCriticalStrike * strikeDamageWhitRate);

            sk.setMax(sk.getCriticalStrike() * roleAttribute.getActMaxRate());
            sk.setMin(sk.getCriticalStrike() * roleAttribute.getActMinRate());
            list.add(sk);
        }

        return list;
    }

}
